package coml.jiyun.hp.day01.fragment;

import androidx.fragment.app.Fragment;

public abstract class BaseFragment extends Fragment {

    protected boolean isVisible;

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (getUserVisibleHint()){
            isVisible=true;
            onVisible();
        }else {
            isVisible=false;
            onInvisible();
        }
    }

    // 懒加载的方法，在这个方法里面为fragment的各个组件去添加数据
    protected  abstract void lazyLoad();
    protected void onVisible(){
        lazyLoad();
    }
    protected void onInvisible(){}
}
